package com.spring.crm.conf;

/**
 * @author Tianshuo
 * @date 2021/1/14 19:59
 */

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5{

    public static String md5(String str) {
        if("".equals(str) || null == str){
            return "";
        }
        MessageDigest md5= null;
        StringBuilder hex = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            byte[] hash;
            hash = MessageDigest.getInstance("MD5").digest(str.getBytes("UTF-8"));

            hex = new StringBuilder(hash.length * 2);
            byte[] arr$ = hash;
            int len$ = hash.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                byte b = arr$[i$];
                if((b & 255) < 16) {
                    hex.append("0");
                }

                hex.append(Integer.toHexString(b & 255));
            }

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return hex.toString();
    }

    public static void  main(String[] a){
        String s = md5("123");
        String s1  = md5("123");
        System.out.print(s1==s);
    }
}

